package com.nf.bookstytem.web.bookmanage;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.nf.bookstytem.model.bookmanage.BookModel;
import com.nf.bookstytem.model.page.PageBookModel;
import com.nf.bookstytem.model.page.Pagination;
import com.nf.bookstytem.service.bookmanage.BookManageService;
import com.nf.bookstytem.uitl.JsonUtil;
@WebServlet("/bookmanage/pagelist")
public class BookPageListServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		BookManageService service=new BookManageService();
		int pageNo=Integer.parseInt(req.getParameter("pageno"));
		int pageSize=5;
		
		List<BookModel>list=service.PageList(pageNo, pageSize);
		int count=service.getPages();
		
		Pagination page=new Pagination(pageNo, pageSize, count);
		
		PageBookModel pagemodel=new PageBookModel();
		pagemodel.setList(list);
		pagemodel.setPagination(page);
		
		String result=JsonUtil.toJson(pagemodel);
		resp.setContentType("application/json;charset=UTF-8");
		resp.getWriter().println(result);
	}
}
